/**
 * 压缩:js  JSMin,非语法解析
 * @param code string 代码
 * @return string
 */
$.astMinEs6 = function(code){
	const EOF='', CS='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_$\\';
	function isCS(v){ return v!==EOF && (CS.indexOf(v)>=0 || v.charCodeAt(0)>126); }
	function GET(run){
		if (run.idx===run.len) return EOF; let x=run.next; run.next=EOF;
		if(x===EOF){ x=run.ipt.charAt(run.idx);  ++run.idx; }
		return x>=' ' || x==='\n' ? x : (x==='\r' ? '\n' : ' ');
	}
	function PEEK(run){ return run.next=GET(run); }
	function NEXT(run){
		let x=GET(run);  if(x!=='/') return x;  let c=PEEK(run);
		if(c==='/') while(true){ x=GET(run); if(x<='\n') return x; }
		if(c!=='*') return x;  GET(run);
		while(true){
			c=GET(run); if(c===EOF) throw new Error('Unterminated comment');
			if(c==='*' && PEEK(run)==='/'){ GET(run);  return ' '; }
		}
	}
	function ACT(run, n){
		let rtn=[];  if(n===1) rtn.push(run.a);
		if(n<3){
			run.a = run.b;
			if (run.a==="'" || run.a==='"') {
				while(true){
					rtn.push(run.a);  run.a=GET(run);
					if(run.a===run.b) break;
					if(run.a<='\n') throw new Error('unterminated string literal: '+run.a);
					if(run.a==='\\'){ rtn.push(run.a);  run.a=GET(run); }
				}
			}
		}
		run.b=NEXT(run);  if(run.b!=='/' || '(,=:[!&|'.indexOf(run.a)<0) return rtn.join('');
		rtn.push(run.a);  rtn.push(run.b);
		while(true){
			run.a=GET(run);  if(run.a==='/') break;
			if(run.a==='\\'){ rtn.push(run.a);  run.a=GET(run); }
			else if(run.a<='\n') throw new Error('unterminated Regular Expression literal');
			rtn.push(run.a);
		}
		run.b=NEXT(run);  return rtn.join('');
	}
	$.astMinEs6 = function(code){
		let run={ipt:code,idx:0,len:code.length,a:'\n',b:'',next:EOF}, rtn=[ACT(run,3)];
		while(run.a!==EOF){
			switch(run.a){
				case ' ': rtn.push(ACT(run,isCS(run.b)?1:2));  break;
				case '\n':
					if(run.b===' ') rtn.push(ACT(run,3));
					else if('{[(+-'.indexOf(run.b)>=0) rtn.push(ACT(run,1));
					else rtn.push(ACT(run,isCS(run.b)?1:2));
					break;
				default:
					switch(run.b){
						case ' ': rtn.push(ACT(run,isCS(run.a)?1:3));  break;
						case '\n':
							if('}])+-"\''.indexOf(run.a)>=0) rtn.push(ACT(run,1));
							else rtn.push(ACT(run, isCS(run.a)?1:3));
							break;
						default: rtn.push(ACT(run,1));  break;
					}
			}
		}
		return rtn.join('').replace(/(^\s*)|(\s*$)/g,'');
	};
	return $.astMinEs6(code);
};
